
// <copyright file="Guard.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The guard.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Validation
{
    using System;

    /// <summary>
    /// The guard.
    /// </summary>
    public static class Guard
    {
        #region Constants

        /// <summary>
        /// The strin g_ mus t_ no t_ b e_ empt y_ exceptio n_ message.
        /// </summary>
        private const string STRING_MUST_NOT_BE_EMPTY_EXCEPTION_MESSAGE = "Argument must not be empty";

        #endregion Constants

        #region Public Methods and Operators

        /// <summary>
        /// The argument not null.
        /// </summary>
        /// <param name="argumentValue">
        /// The argument value.
        /// </param>
        /// <param name="parameterName">
        /// The parameter name.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        public static void ArgumentNotNull(object argumentValue, string parameterName)
        {
            if (argumentValue == null)
            {
                throw new ArgumentNullException(parameterName);
            }
        }

        /// <summary>
        /// The argument not null.
        /// </summary>
        /// <param name="argumentValue">
        /// The argument value.
        /// </param>
        /// <param name="parameterName">
        /// The parameter name.
        /// </param>
        /// <param name="detailedMessage">
        /// The detailed message.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        public static void ArgumentNotNull(object argumentValue, string parameterName, string detailedMessage)
        {
            if (argumentValue == null)
            {
                throw new ArgumentNullException(parameterName, detailedMessage);
            }
        }

        /// <summary>
        /// The argument not null or empty.
        /// </summary>
        /// <param name="argumentValue">
        /// The argument value.
        /// </param>
        /// <param name="parameterName">
        /// The parameter name.
        /// </param>
        public static void ArgumentNotNullOrEmpty(string argumentValue, string parameterName)
        {
            ArgumentNotNullOrEmpty(argumentValue, parameterName, STRING_MUST_NOT_BE_EMPTY_EXCEPTION_MESSAGE);
        }

        /// <summary>
        /// The argument not null or empty.
        /// </summary>
        /// <param name="argumentValue">
        /// The argument value.
        /// </param>
        /// <param name="parameterName">
        /// The parameter name.
        /// </param>
        /// <param name="detailedMessage">
        /// The detailed message.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        /// <exception cref="ArgumentException">
        /// </exception>
        public static void ArgumentNotNullOrEmpty(string argumentValue, string parameterName, string detailedMessage)
        {
            if (argumentValue == null)
            {
                throw new ArgumentNullException(parameterName);
            }

            if (argumentValue.Length == 0)
            {
                throw new ArgumentException(detailedMessage, parameterName);
            }
        }

        /// <summary>
        /// The argument not null or empty or white space.
        /// </summary>
        /// <param name="argumentValue">
        /// The argument value.
        /// </param>
        /// <param name="parameterName">
        /// The parameter name.
        /// </param>
        public static void ArgumentNotNullOrEmptyOrWhiteSpace(string argumentValue, string parameterName)
        {
            ArgumentNotNullOrEmptyOrWhiteSpace(argumentValue, parameterName, STRING_MUST_NOT_BE_EMPTY_EXCEPTION_MESSAGE);
        }

        /// <summary>
        /// The argument not null or empty or white space.
        /// </summary>
        /// <param name="argumentValue">
        /// The argument value.
        /// </param>
        /// <param name="parameterName">
        /// The parameter name.
        /// </param>
        /// <param name="detailedMessage">
        /// The detailed message.
        /// </param>
        /// <exception cref="ArgumentException">
        /// </exception>
        public static void ArgumentNotNullOrEmptyOrWhiteSpace(string argumentValue, string parameterName, string detailedMessage)
        {
            ArgumentNotNull(argumentValue, parameterName, detailedMessage);
            for (int i = 0; i < argumentValue.Length; i++)
            {
                if (!char.IsWhiteSpace(argumentValue[i]))
                {
                    return;
                }
            }

            throw new ArgumentException(detailedMessage, parameterName);
        }

        #endregion Public Methods and Operators
    }
}
